//
//  FLBaseHttpsRequest.m
//  FruitsWholesaler
//
//  Created by sgone-2 on 16/4/21.
//  Copyright © 2016年 sgone. All rights reserved.
//

#import "FLBaseHttpsRequest.h"
#import "AFNetworking.h"
#import "Toast+UIView.h"

@interface FLBaseHttpsRequest (){
    
    
}

@property (nonatomic, strong)AFHTTPSessionManager *manager;


@end

@implementation FLBaseHttpsRequest


- (AFHTTPSessionManager *)manager {
    
    if (_manager == nil) {
        _manager = [AFHTTPSessionManager manager];
    }
    return _manager;
}


/**
 *  向服务器发送请求
 *
 *  @param url          服务器地址
 *  @param dic          服务器所需参数
 *  @param successBlock 请求成功返回值
 *  @param errorBlock   请求失败返回值
 */


-(void)sendHttpRequest:(NSString *)url parameters:(NSDictionary *)dic success:(RequestHttpSuccessBlock)successBlock error:(RequestHttpErrorBlock)errorBlock
{

  [self.manager POST:url parameters:dic success:^(NSURLSessionDataTask *task, id responseObject) {

      if ([responseObject[@"error_flag"]intValue] == 0) {
          
          successBlock([responseObject objectForKey:@"data"]);
          

      }
      else
      {
      
         errorBlock(responseObject[@"result_msg"]);
          
          
      }
      
      
//      successBlock ([responseObject objectForKey:@"error_flag"]);
      
      
      
      
      
  } failure:^(NSURLSessionDataTask *task, NSError *error) {
      
      errorBlock(@"网络请求有误");
      
  }];



}

@end
